<?php
	session_start();
	require 'include/configDB.php';

	if (!isset($_SESSION['role']) || (($_SESSION['role'] != "Guru") && ($_SESSION['role'] != "Admin"))) {
		// redirect ke page login
		header('Location: login.php');
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Input Guru</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">
	
	function cekuser(a) {
	re = /^[a-zA-Z\s]+$/;
	return re.test(a);
	}

	function phonenumber(inputtxt)  
	{  
	  var reg = new RegExp("^[0][0-9]{7,14}([ ]?[\\,|\\;][ ]?[0][0-9]{7,14})*$");

	  return reg.test(inputtxt);
	} 

	function allNumber(input){
		var numbers = /^[0-9]+$/;
		return numbers.test(input);
	}

	function alphaNumeric(input){
		var letters = /^[0-9a-zA-Z]+$/;
		return letters.test(input);
	}

	function validasi() {
		var NIK = document.getElementById("NIK").value;
		var nama = document.getElementById("nama").value;
		var tempat_lahir = document.getElementById("tempat_lahir").value;
		var agama = document.getElementById("agama").value;
		var alamat = document.getElementById("alamat").value;
		var no_tlp = document.getElementById("notlp").value;
		var keahlian = document.getElementById("keahlian").value;

		if (NIK == "") {
			alert("NIK harus diisi");
			return false;
		}

		if (nama == "") {
			alert("Nama harus diisi");
			return false;
		}

		if (tempat_lahir == "") {
			alert("Tempat lahir harus diisi");
			return false;
		}

		if (document.input_data_guru.tanggal_lahir.value == "NULL") {
			alert("Tanggal Lahir harus diisi");
			return false;
		}

		if (document.input_data_guru.bulan_lahir.value == "NULL") {
			alert("Bulan lahir harus diisi");
			return false;
		}

		if (document.input_data_guru.tahun_lahir.value == "NULL") {
			alert("Tahun lahir harus diisi");
			return false;
		}

		if (agama == "") {
			alert("Agama harus diisi");
			return false;
		}

		if (alamat == "") {
			alert("Alamat harus diisi");
			return false;
		}

		if (document.input_data_guru.kode_pos.value == "NULL") {
			alert("kodepos harus diisi");
			return false;
		}

		if (no_tlp == "") {
			alert("Nomor Telepon harus diisi");
			return false;
		}

		if (document.input_data_guru.pend_terakhir.value == "NULL") {
			alert("Pendidikan Terakhir guru harus diisi");
			return false;
		}

		if (keahlian == "") {
			alert("Nomor Telepon harus diisi");
			return false;
		}

		if (!allNumber(NIK)) {
			alert("NIK harus berupa nomor semua!");
			return false;
		}


		if (cekuser(nama)) {
			return true;
		}else{
			alert("Nama harus berupa HURUF semua! ");
			return false;
		}


		if (!cekuser(tempat_lahir)) {
			alert("Tempat Lahir harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(agama)) {
			alert("Agama harus berupa HURUF semua! ");
			return false;
		}

		if (!alphaNumeric(alamat)) {
			alert("Alamat tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if(!phonenumber(no_tlp)){
			alert("No Telepon harus berupa Angka semua! ");
			return false;
		}

		if (!cekuser(keahlian)) {
			alert("Keahlian harus berupa HURUF semua! ");
			return false;
		}
	}
</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">  
		
    
	
    <div class="left_content">
    
    		<?php include 'left_content.php'; ?>
    		<?php include 'calendar.php' ; ?>

    </div>  
    
    <div class="right_content">
		<h2>Input Data Guru</h2>
     	<div id="stylized" class="myform">
         	<form id="input_data_guru" name="input_data_guru" method="post" action="include/input_data_guru.php" onsubmit='return validasi();'>
        		<h1>Guru</h1>
      			<table>
					<tr>
					<td width="250">
						<label>NIK<span class="small">Nomor Induk Karyawan</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="number" class="input_text" name="NIK" id="NIK">
					</td>
					</tr>
					<tr>
						<td>
							<label>Nama Lengkap
							<span class="small">Isi Nama guru</span></label>
						</td>
						<td>
							:
						</td>
						<td colspan="3">
							<input type="text" class="input_text" name="nama" id="nama">
						</td>
					</tr>
					<tr>
					<td>
						<label> Tempat lahir<span class="small">Tempat lahir guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type = "text" name = "tempat_lahir" id = "tempat_lahir"/>
					</td>
			   </tr>
			   <tr> 
					<td>  
						<label> Tanggal Lahir<span class="small">Tanggal lahir/Bulan Lahir/Tahun Lahir guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">    
					   <select name='tanggal_lahir' id='tanggal_lahir'>
					   	<option value="NULL">Pilih</option>
						<?php 
							for ($i = 1; $i <= 31; $i++) {
								?>
								<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php
							}
						?>
						</select>
					   <select name='bulan_lahir' id='bulan_lahir'>
					   	<option value="NULL">Pilih</option>
						 <?php 
							for ($i = 1; $i < 13; $i++) {
								?>
								<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php
							}
						?>
						</select>
						<select name='tahun_lahir' id='tahun_lahir'>
						<option value="NULL">Pilih</option>
						<?php 
						for ($i = 2000; $i >= 1985; $i--) {
							?>
							<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php
						}
						?>
						</select>
					</td>
				</tr>
				<tr>
					<td>
						<label>Agama<span class="small">Agama guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="text" name="agama" id="agama" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Jenis Kelamin<span class="small">Isi jenis kelamin guru</span></label>
					</td>
					<td>
						:
					</td>
					<td>  
						<input type="radio" name="jenis_kelamin" value="laki-laki">Laki-laki
					</td>
					<td >
						<input type="radio" name="jenis_kelamin" value="perempuan">Perempuan
					</td>
				</tr>

				<tr>
					<td>
						<label>Alamat<span class="small">Alamat guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<textarea rows="5" cols="24" name="alamat" id="alamat"></textarea>
					</td>
				</tr>
				<tr>
					<td>
						<label>Kodepos<span class="small">Pilih kodepos guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<select name="kode_pos" id="kode_pos">
							<option value="NULL">---------Pilih----------</option>
							<?php 
						        $kode_pos = mysql_query("SELECT * FROM kode_pos");  
						        while($kode_pos_data = mysql_fetch_assoc($kode_pos))
						        {
						   		?> 
        							<option value="<?= $kode_pos_data['kode_pos']; ?>"><?= $kode_pos_data['kode_pos']?></option>  
								<?php  
								}  
								?>  	
					    </select>		
					</td>
				</tr>
					<tr>
						<td><label>Email<span class="small">Alamat Email</span></label>
					</td>
					<td>
						:
					</td>
					</td>
					<td colspan="3">
						<input type="email" name="email" id="email"/>
					</td>
			   </tr>
				<tr>
					<td>
					<label>No Telepon/HP
						<span class="small">Isi nomor telepon/HP</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">	
						<input type="tel" class="input_text" name="notlp" id="notlp">
					</td>
				</tr>
				<tr>
					<td>
						<label>Status<span class="small">Status guru</span></label>
					</td>
					<td>
						:
					</td>
					<td width = "100">  
						<input type="radio" name="status" value="kawin">Kawin
					</td>
					<td >
						<input type="radio" name="status" value="Tidak Kawin">Tidak Kawin
					</td>
				</tr>
				<tr>
					<td>
					<label>Pendidikan Terakhir
						<span class="small">Pendidikan Terakhir guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">	
						<select name="pend_terakhir" id="pend_terakhir">
							<option value="NULL">---------Pilih----------</option>
							<option value="D3">D3</option>
							<option value="S1">S1</option>
							<option value="S2">S2</option>
							<option value="S3">S3</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>
					<label>Keahlian
						<span class="small">Keahlian guru</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">	
						<input type="text" class="input_text" name="keahlian" id="keahlian">
					</td>
				</tr>
				<tr>
				</tr>
				<tr>
                  <td><input type="submit" name="submit" class="menuitem_red" value="Tambah"/></td>
                </tr> 					
				</table>
          <div class="spacer"></div>
          </form>
		</div>
    </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
    
    	    	<?php include 'footer.php'; ?>

    </div>

</div>		
</body>
</html>
